<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="工人姓名" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入姓名"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="质检人" prop="zhijianUser">
              <el-input v-model="queryParams.zhijianUser" placeholder="请输入质检人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="项目编号" prop="projectCode">
                <el-input v-model="queryParams.projectCode" placeholder="请输入项目编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品编号" prop="goodsCode">
                <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="产品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="工序名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入姓名"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="质检时间" prop="zhijianDate">
              <el-date-picker clearable v-model="queryParams.zhijianDate"
                              type="date" value-format="yyyy-MM-dd" placeholder="请选择质检时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              <!--<el-button type="warning" plain icon="el-icon-download" size="mini"
                         @click="handleExport" >导出
              </el-button>-->
            </el-form-item>
        </el-form>

       <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-popconfirm title="确认选择批量质检的数据项？" @confirm="handleZhijianAll({})">
                    <el-button slot="reference" type="success" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:reportRecord:pilQualitBnt']">批量报工质检合格</el-button>
                </el-popconfirm>
            </el-col>
          <el-col :span="1.5">
            <el-popconfirm title="确认选择批量质检的数据项？" @confirm="handleZhijianAllNo({})">
              <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                         v-hasPermi="['develop:reportRecord:pilQualitBnt']">批量报工质检不合格</el-button>
            </el-popconfirm>
          </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight"  @sort-change="handleSortChange">
            <el-table-column type="selection" width="55" align="center"/>
                <el-table-column sortable label="报工时间" align="center" prop="doTime" width="180">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.doTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column sortable label="质检日期" align="center" prop="zhijianDate" width="180">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.zhijianDate, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column sortable label="质检人" align="center" prop="zhijianUser"/>
                <el-table-column sortable label="项目编号" align="center" prop="projectCode"/>
                <el-table-column sortable label="产品编号" align="center" prop="goodsCode"/>
                <el-table-column sortable label="产品名称" align="center" prop="goodsName" show-overflow-tooltip/>
                <el-table-column sortable label="产品型号" align="center" prop="goodsModel"/>
                <el-table-column sortable label="工序名称" align="center" prop="name"/>
                <el-table-column sortable label="姓名" align="center" prop="userName"/>
                <el-table-column sortable label="报工数量" align="center" prop="count"/>
                <el-table-column sortable label="合格数量" align="center" prop="successCount"/>
                <el-table-column sortable label="不合格数量" align="center" prop="errorCount"/>
                <el-table-column sortable label="合格总价" align="center" prop="allMoney"/>
                <el-table-column sortable label="合格率(%)" align="center" prop="successLv"/>
                <el-table-column align="center" label="状态" prop="status">
                  <template slot-scope="scope">
                    <dict-tag :options="dict.type.baogong_status" :value="scope.row.status"/>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <!--<template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:reportRecord:editBnt']">修改</el-button>
                  <el-button size="mini" type="text" icon="el-icon-edit"
                             @click="zhijian(scope.row)" v-hasPermi="['develop:reportRecord:qualityBnt']">质检</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:reportRecord:removeBnt']">删除</el-button>
                    </el-popconfirm>
                </template>-->
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

      <goodsSaledoGongxuUserMoney-form ref="form" @ok="getList"></goodsSaledoGongxuUserMoney-form>
      <zhijianGongxu-form ref="zhijianForm" @ok="getList"></zhijianGongxu-form>
    </div>
</template>

<script>
    import { deleteAction, getAction,downloadFile } from '@/api/manage'
    import GoodsSaledoGongxuUserMoneyForm from '@/views/develop/goodsSaledoGongxuUserMoney/module/GoodsSaledoGongxuUserMoneyForm'
    import ZhijianGongxuForm from '@/views/develop/goodsSaledoGongxuUserMoney/module/ZhijianGongxuForm'
    import { list } from "@/api/develop/goodsSaledoGongxuUserMoney";

    export default {
        name: "GoodsSaledoGongxuUserMoneyZhijian",
        dicts: ['baogong_status'],
        components: {
            GoodsSaledoGongxuUserMoneyForm,
            ZhijianGongxuForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 报工列表格数据
                dataList: [],
                dateRange: [],
                // 查询参数
                queryParams: {
                    name:null,
                    goodsName:null,
                    goodsCode:null,
                    projectCode: null,
                    pageNum: 1,
                    pageSize: 10,
                    xuhao: null,
                    doTime: null,
                    userId: null,
                    userName: null,
                    money: null,
                    count: null,
                    allMoney: null,
                    parentId: null,
                    successCount: null,
                    errorCount: null,
                    successLv: null,
                    status: "2",
                    zhijianDate: null,
                    zhijianUser: null,
                    zhijianId: null
                },
                url: {
                    list:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/listAndParent',
                    removeUpdate:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/removeUpdate/',
                    export:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/export',
                    zhijianAllUpdate:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/zhijianAllUpdate/',
                    zhijianAllNoUpdate:'/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/zhijianAllNoUpdate/',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 排序触发事件 */
            handleSortChange(column, prop, order) {
            this.queryParams.orderByColumn = column.prop;
            this.queryParams.isAsc = column.order;
            this.handleQuery();
            },
            /** 查询报工列列表 */
            getList() {
                this.loading = true;
                list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
                //getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.dateRange = [];
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            zhijian(row) {
              this.$refs.zhijianForm.zhijianShow(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.removeUpdate, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
              let that = this;
              that.loading = false;
              that.$confirm('是否确认报工信息表?', "确认", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
              }).then(function () {
                downloadFile('/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/exportGz', that.queryParams);
              });
            },
            handleZhijianAll(){
              const ids = this.ids;
              deleteAction(this.url.zhijianAllUpdate, ids).then(response => {
                this.getList();
                this.$modal.msgSuccess("批量质检成功！");
              }).catch(() => {});
            },
          handleZhijianAllNo(){
            const ids = this.ids;
            deleteAction(this.url.zhijianAllNoUpdate, ids).then(response => {
              this.getList();
              this.$modal.msgSuccess("批量质检成功！");
            }).catch(() => {});
          },
    }
};
</script>
